package Array;

import java.util.Arrays;

public class MaoPao {
    public static void main(String[] args) {
        int[] arr = {10, 44, 23, 242, 111, 2, 0};
        maopao1(arr);
//        maopao2(arr);
    }

    public static void maopao1(int[] arr) {//最大值向后冒
        for (int i = 0; i < arr.length - 1; i++) {//轮数
            for (int j = 0; j < arr.length - 1 - i; j++) {//当前这轮的比较次数
                if (arr[j] > arr[j + 1]) {                 //第i轮就意味着确定了i个大值
                    int t = arr[j];                     //所以比较次数-i
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
    public static void maopao2(int[] arr) {//最小值向前冒
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i+1; j < arr.length ; j++) {
                if (arr[i] > arr[j ]) {
                    int t = arr[j];
                    arr[j] = arr[i];
                    arr[i] = t;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}